home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-11 | 6.4 KB | 237 lines | [TEXT/CWIE] |
- /***
- File: Credits.c
-
-
- Contains: Generic code for credits splash
-
-
- Written by: Ken Wieschhoff
-
-
- Copyright: ©1996 Siren Enterprises, All Rights Reserved.
-
-
- Change History (most recent first):
-
-
-
- <1> 9/5/96 kw Original
-
- ***/
-
-
-
- long gNextCredits;
- short gTextOffset;
- long gNextCredits;
-
- pascal void DrawCredits(DialogPtr theDialog,PicHandle creditsPicture, short *textOffset);
- pascal QDErr MyNewGWorld(GWorldPtr *offscreenGWorld,short PixelDepth,const Rect *boundsRect,
- CTabHandle cTable,GDHandle aGDevice,GWorldFlags flags);
- short FindStringHeight( Str255 theString, short theFont, short theFace, short theSize );
- short FindChar( char theChar, Str255 theString, short index, Str255 partialString );
- void MyDrawString( Str255 theString, Point topLeft, short theFont, short theFace, short theSize );
-
- /*==================================================================================*/
- pascal void DrawCredits(DialogPtr theDialog,PicHandle creditsPicture, short *textOffset) {
-
- Rect itsRect;
- Rect creditsWorldRect;
- Str255 credits;
- short itsID;
- Point where;
- GWorldPtr creditsGWorld = NULL;
- PixMapHandle creditsPixmap;
- OSErr err = noErr;
- CGrafPtr oldPort = NULL;
- GDHandle oldGDevice;
- RGBColor oldColor;
- RGBColor briteWhite = { 0xFFFF, 0xFFFF, 0xFFFF };
- RgnHandle itsClip = NewRgn();
- RgnHandle oldClip = NewRgn();
- short stringHeight;
-
- if ( TickCount() < gNextCredits)
- return;
-
- gNextCredits = TickCount() + 5;
-
- GetFNum("\pPalatino", &itsID);
-
- // Get the credits from a string resource.
- GetIndString( credits, 128, 4);
-
- // Get the rect of this dialog item (GetDitem)
- itsRect = creditsWorldRect = (**creditsPicture).picFrame;
-
- // Create a GWorld in which to image the picture offscreen.
- err = MyNewGWorld( &creditsGWorld, 0, &creditsWorldRect, NULL, NULL, 0);
-
- if ( err == noErr) {
-
- // Save the old GWorld
- GetGWorld( &oldPort, &oldGDevice);
-
- // Set to our new GWorld
- SetGWorld( creditsGWorld, NULL);
-
- // Set up ahead of time by "gCreditsPicture = (PicHandle)GetResource( 'PICT', 128);"
- if ( creditsPicture)
- DrawPicture( creditsPicture, &(**creditsPicture).picFrame);
- else
- EraseRect( &creditsWorldRect);
-
- // Routine to find the text height for a string with embedded carriage returns
- stringHeight = FindStringHeight( credits, itsID, bold, 12);
-
- if (*textOffset < (itsRect.top - stringHeight)) {
- *textOffset = itsRect.bottom;
- }
-
- SetPt( &where, itsRect.left, itsRect.top + (*textOffset)--);
-
- GetForeColor( &oldColor);
- RGBForeColor( &briteWhite);
-
- GetClip( oldClip);
- RectRgn( itsClip, &itsRect);
-
- // Clip to this area
- SetClip( itsClip);
-
- // Draws the string
- MyDrawString( credits, where, itsID, bold, 12);
-
- SetClip( oldClip);
- RGBForeColor( &oldColor);
-
- // Blast the GWorld onto the dialog.
- creditsPixmap = GetGWorldPixMap( creditsGWorld);
- if ( LockPixels( creditsPixmap)) {
- CopyBits ( (BitMap *)*creditsPixmap, &theDialog->portBits,
- &creditsWorldRect, &creditsWorldRect, srcCopy, nil);
- UnlockPixels( creditsPixmap);
- }
- }
-
- if ( creditsGWorld)
- DisposeGWorld( creditsGWorld);
-
- if ( oldPort)
- SetGWorld( oldPort, oldGDevice);
-
- if ( itsClip)
- DisposeRgn( itsClip);
-
- if ( oldClip)
- DisposeRgn( oldClip);
-
- return;
-
- }
-
- /*======================================================================*/
- pascal QDErr MyNewGWorld(GWorldPtr *offscreenGWorld,short PixelDepth,const Rect *boundsRect,
- CTabHandle cTable,GDHandle aGDevice,GWorldFlags flags) {
-
- QDErr err = noErr;
-
- err = NewGWorld(offscreenGWorld, PixelDepth, boundsRect,
- cTable, aGDevice, flags);
- if ( err == memFullErr)
- err = NewGWorld(offscreenGWorld, PixelDepth, boundsRect,
- cTable, aGDevice, flags | useTempMem);
- return( err);
- }
-
- /*==================================================================================*/
- short FindStringHeight( Str255 theString, short theFont, short theFace, short theSize ) {
-
- GrafPtr thePort;
- short saveFont;
- short saveFace;
- short saveSize;
- FontInfo fInfo;
- short lineHeight;
- short lineBase;
- short crIndex;
- Str255 lineString;
-
- GetPort( &thePort );
- saveFont = thePort->txFont;
- saveFace = thePort->txFace;
- saveSize = thePort->txSize;
- TextFont( theFont );
- TextFace( theFace );
- TextSize( theSize );
- GetFontInfo( &fInfo );
- lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
- lineBase = fInfo.ascent + fInfo.descent;
- crIndex = FindChar( 0x0D, theString, 1, lineString );
- while( crIndex < theString[0] ) {
- lineBase += lineHeight;
- crIndex = FindChar( 0x0D, theString, crIndex + 1, lineString );
- }
- thePort->txFont = saveFont;
- thePort->txFace = saveFace;
- thePort->txSize = saveSize;
-
- return( lineBase);
-
- }
- /*==================================================================================*/
- short FindChar( char theChar, Str255 theString, short index, Str255 partialString ) {
- /* Searches for the specified char from the indexth mark in theString. Also stops */
- /* at the strings end. partialString will be set to a pascal string with all the */
- /* intermediate chars (it does not include the one being searched for). */
-
- short newIndex;
-
- newIndex = index;
- while( newIndex <= theString[0] && theString[newIndex] != theChar )
- newIndex++;
-
- partialString[0] = newIndex - index;
- BlockMove( &theString[index], &partialString[1], partialString[0] );
-
- return( newIndex );
- }
- /*==================================================================================*/
- void MyDrawString( Str255 theString, Point topLeft, short theFont, short theFace, short theSize ) {
-
- GrafPtr thePort;
- short saveFont;
- short saveFace;
- short saveSize;
- FontInfo fInfo;
- short lineHeight;
- short lineBase;
- short crIndex;
- Str255 lineString;
-
- GetPort( &thePort );
- saveFont = thePort->txFont;
- saveFace = thePort->txFace;
- saveSize = thePort->txSize;
- TextFont( theFont );
- TextFace( theFace );
- TextSize( theSize );
- GetFontInfo( &fInfo );
- lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
- lineBase = fInfo.ascent + fInfo.descent;
- MoveTo( topLeft.h, topLeft.v + lineBase );
- crIndex = FindChar( 0x0D, theString, 1, lineString );
- while( crIndex < theString[0] ) {
- DrawString( lineString );
- lineBase += lineHeight;
- MoveTo( topLeft.h, topLeft.v + lineBase );
- crIndex = FindChar( 0x0D, theString, crIndex + 1, lineString );
- }
- DrawString( lineString );
- thePort->txFont = saveFont;
- thePort->txFace = saveFace;
- thePort->txSize = saveSize;
- }
- /*==================================================================================*/
-
-